export default function useValidation() {
  function required(value, field) {
    return !!value || `* ${field} field is required.`;
  }

  function email(value) {
    const regex = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return regex.test(value) || 'Email format is not valid.';
  }

  function phone(value) {
    const phoneRegex = /^1[3-9]\d{9}$/; // 示例手机号正则
    return phoneRegex.test(value) || '手机号格式不正确';
  }

  function minLength(value, min) {
    return value ? (value.length >= min || `至少需要${min}个字符`) : true;
  }

  function maxLength(value, max) {
    return value ? (value.length <= max || `最多允许${max}个字符`) : true;
  }
  return {
    required, email, phone, minLength, maxLength,
  };
}
